package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.Sign;
import cn.wolfcode.trip.base.domain.SignDetail;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.ISignService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sign")
public class SignController {

    @Autowired
    private ISignService signService;

    @Autowired
    private IUserService userService;

    @PostMapping
    public JSONResult save(Sign sign){
        JSONResult result=new JSONResult();
        sign.setUser(UserContext.getCurrentUser());
        try {
            signService.saveSign(sign);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    @GetMapping(value = "/signDetail")
    public List<SignDetail> getDetail(Long id){
        return signService.getAllSignDetailByUserId(id);
    }

    @GetMapping
    public Sign getSign(Long id){
        return signService.getSign(id);
    }


    @GetMapping(value = "/integral")
    public User getSignIntegral(Long id){
        return userService.selectIntegralById(id);
    }



}
